const jwt = require("jsonwebtoken")

let secretKey = "chenxinliang"
const optionDefault = {
    expiresIn: '1h'
}

//  payload:数据   options : 参数
const signToken = (payload, options=optionDefault)=>{
    console.log('生产token',payload);
    return jwt.sign(payload, secretKey, options)
}

const verifyToken = (token)=>{
    return jwt.verify(token, secretKey, (err,decoded)=>{
        if(err){
            console.log(err);
            return
        }
        console.log("校验通过",decoded);
        return decoded
    })
}

module.exports = {
    signToken,verifyToken
}